﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Windows;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void YGRPDC(DataSet db)
        {
            int x = 2, y = 1;
            DataTable dtOutput = new DataTable();
            try
            {
                #region======Title===========
                int idx = 1;
                int start = 1;
                /*PDCDATE	JP10	ABFAUFKRS	ABFAUFLFD	ABFAUFPOS	ABPART	ABPFARBE	
                        AMBDEMA	PDCSTAFF	PDCSHIFT	QTY	AMAUFTRVON	JP03	JP02	JP06	JP12*/
                exAgent.SetCellValue(start, idx++, "日期"); dtOutput.Columns.Add("DAT", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "产量日期"); dtOutput.Columns.Add("PDCDATE", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "批号"); dtOutput.Columns.Add("JP10", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "前缀"); dtOutput.Columns.Add("ABFAUFKRS", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "订单号"); dtOutput.Columns.Add("ABFAUFLFD", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "行号"); dtOutput.Columns.Add("ABFAUFPOS", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "纱线编号"); dtOutput.Columns.Add("ABPART", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "色号"); dtOutput.Columns.Add("ABPFARBE", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "机台号"); dtOutput.Columns.Add("AMBDEMA", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "标注"); dtOutput.Columns.Add("JP14", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "档车工"); dtOutput.Columns.Add("PDCSTAFF", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "班次"); dtOutput.Columns.Add("PDCSHIFT", typeof(System.Decimal));
                exAgent.SetCellValue(start, idx++, "数量"); dtOutput.Columns.Add("QTY", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "入工数"); dtOutput.Columns.Add("AMAUFTRVON", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "出工数"); dtOutput.Columns.Add("JP03", typeof(System.Decimal));
                exAgent.SetCellValue(start, idx++, "实开锭数"); dtOutput.Columns.Add("JP02", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "KM"); dtOutput.Columns.Add("JP06", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "号数"); dtOutput.Columns.Add("JP12", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "落纱次数"); dtOutput.Columns.Add("JP28", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "折合落纱"); dtOutput.Columns.Add("JP15", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "落纱姓名"); dtOutput.Columns.Add("JP20", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "换纱个数"); dtOutput.Columns.Add("JP24", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "铺台个数"); dtOutput.Columns.Add("JP26", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "生头个数"); dtOutput.Columns.Add("JP27", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "折合换纱"); dtOutput.Columns.Add("JP16", typeof(System.String));
                exAgent.SetCellValue(start, idx++, "换纱姓名"); dtOutput.Columns.Add("JP25", typeof(System.String));
                #endregion
                
                exAgent.SetCurrentSheet("YGRPDC");
                exAgent.CopySheet("细纱");                
                dtOutput.Merge(db.Tables["ICC_PDC"], false, MissingSchemaAction.Ignore);
                DataRow dwData = VHR.TBMain.NewRow();
                dwData["HRMANDANT"] = app.Mandant;
                //到报表程序的用户管理地方，在其他编号的地方进行管理
                DataSet SResult = VHR.QHR06(dwData);
                DataTable TBHR = SResult.Tables[0].Copy();
                /*
                foreach (DataRow row in dtOutput.Rows)
                {
                    string staff = row["PDCSTAFF"].ToString();
                    staff = staff + "/";
                    staff = staff.Replace("/", ",");
                    string[] staffs = staff.Split(',');
                    staff = "";
                    foreach(string hr in staffs)
                    {
                        if (hr.Trim() == "") continue;
                        string filter = "TRIM(HRGNAME)='" + hr.Trim() + "'";
                        DataRow[] rows = TBHR.Select(filter);
                        if(rows.Length>0)
                        {
                            staff += GetGB2312Value(rows[0]["HRVNAME"].ToString()).Trim()+"/";
                        }
                    }
                    staff += "***";
                    staff = staff.Replace("/***", "");
                    if (staff == "" || staff == "***")
                    {
                    }
                    else
                    {
                        row["PDCSTAFF"] = staff;
                    }
                    
                }*/
                int count = dtOutput.Rows.Count;
                exAgent.DataTableToExcel(dtOutput, x, 1);
                exAgent.SetCellValue(1, 1, 1);
                exAgent.BatchConvert2Number(2, 13, count + 1, 20);
                exAgent.BatchConvert2Number(2, 22, count + 1, 25);
                exAgent.SetCellValue(1, 1, "日期");                
                
                exAgent.DeleteSheet("YGRPDC");
                exAgent.SetCurrentSheet("细纱");
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
        }

    }
}